package com.example.demo.controller;

import com.example.demo.entity.ImageRecognitionHistory;
import com.example.demo.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/api/image")
public class ImageController {

    @Autowired
    private ImageService imageService;

    // 上传图片
    @PostMapping("/upload")
    public Map<String, Object> uploadImage(@RequestParam("file") MultipartFile file) throws IOException {
        return imageService.uploadImage(file);  // 调用服务层处理上传
    }

    // 识别图片
    @GetMapping("/recognize")
    public Map<String, Object> recognizeImage(@RequestParam("fileName") String fileName) throws IOException {
        return imageService.recognizeImage(fileName);  // 调用服务层处理识别
    }

    // 查询历史记录
    @GetMapping("/history")
    public List<ImageRecognitionHistory> getHistory() {
        return imageService.getHistory();  // 获取所有历史记录
    }
}
